<?php

class RegistrationController extends Controller_Site //Controller_Site
{
	public function indexAction()
	{

	}

	/**
	 * Registration main method.
	 *
	 * @return void
	 */
	public function registerAction()
	{
		//$this->_ajaxOnly();
//		$login = $this->_getParam('login');
//		$email = $this->_getParam('email');
//		$password = $this->_getParam('password');
//		$repeatPass = $this->_getParam('repeat_password');
		$params = $this->_getAllParams();
		$input = ValidationService::getInstance()->getRegistrationInputFilterChain();
		
		$input->setData($params);
		if (!$input->isValid()) {
			$messages = $input->getMessages();
			$this->view->result = array("success" => false, "errors" => $messages); 
			return;
		}
		$adapter = Db::getConnection();
		$adapter->beginTransaction();
		try {
			
			$sql_params = array(
							"email"  => $input->getEscaped('email'),
							"first_name" => $input->getUnescaped('first_name'),
							'password' => $this->getProfileService()->encryptSha1Password($input->getEscaped('password')),
							'status' => 1
			);
	
			$row = $this->getProfileService()->registerNewUser($sql_params);
			$adapter->commit();
			$this->view->result = array("success" => true);
			return; 
		} catch (Exception $e) {
			$e->getMessage();
			$this->view->result = array("success" => false, "errors" => "В процессе регистрации произошла ошибка"); 
			return;
		}	
	}
	
	
}
